package com.humble.test;/*
  humble keep gonging
*/

import com.humble.bean.furn;
import com.humble.dao.furnMapper;


import com.humble.service.FurnService;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.InvalidConfigurationException;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class humbText {
    private static ApplicationContext  context;

    @BeforeAll
    public static void init(){
        context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
    }
    @Test
    public void test(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        Object bean = context.getBean("pooledDataSource");
        System.out.println(bean);
        Object bean1 = context.getBean("sqlSessionFactory");
        System.out.println(bean1);
    }

    @Test
    public void test2() throws XMLParserException, IOException, InvalidConfigurationException, SQLException, InterruptedException {
        List<String> warnings = new ArrayList<String>();
        boolean overwrite = true;
        File configFile = new File("mybatis-generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }

    @Test
    public void test3(){
        ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml");
        furnMapper mapper = context.getBean(furnMapper.class);
        furn furn = new furn();
        furn.setImgPath("images/product/5.jpg");
        furn.setId(5);
        mapper.updateByPrimaryKeySelective(furn);
//        furn.setMaker("京东家居");
//        furn.setName("大沙发");
//        furn.setImgPath("img/product/5.jpg");
//        furn.setPrice(new BigDecimal(1800));
//        furn.setStock(100);
//        furn.setSales(8);
//        mapper.insertSelective(furn);
    }

    @Test
    public void test4(){
        FurnService bean = context.getBean(FurnService.class);
        furn furn = new furn(null, "电风扇", "格力", new BigDecimal(200), 200, 9, "");
        bean.save(furn);
    }

    @Test
    public void test5(){
        FurnService bean = context.getBean(FurnService.class);
        List<furn> allFurns = bean.getAllFurns();
        for (furn furn : allFurns) {
            System.out.println(furn);
        }
    }
    @Test
    public void test6(){
        FurnService service = context.getBean(FurnService.class);
        furn furn = new furn(13, "充电器", "华为", new BigDecimal(50), 1000, 500, null);
        service.update(furn);
    }

    @Test
    public void test7(){
        FurnService service = context.getBean(FurnService.class);
        service.delete(13);
    }

    @Test
    public void test8(){
        FurnService service = context.getBean(FurnService.class);
        List<furn> furnByName = service.getFurnByName("桌子");
        for (furn furn : furnByName) {
            System.out.println(furn);
        }
    }
    @Test
    public void test9(){
        char a='n';
        int b=a%26;
        System.out.println(b);
        HashSet<Integer> set = new HashSet<Integer>();
        set.toArray(new Integer[0]);
    }
}
